// ContactsForm.h : Declaration of the CContactsForm

#pragma once

#include "resource.h"       // main symbols
#include <WindowsX.h>

#include <atlhost.h>
#include <string>
#include <vector>

using namespace ATL;

// CContactsForm

class CContactsForm : 
	public CAxDialogImpl<CContactsForm>
{
public:

	CContactsForm(Outlook::_Application* app)
	{
		m_app = app;
	}

	CContactsForm()
	{
		m_app = NULL;
	}

	~CContactsForm()
	{
	}

	enum { IDD = IDD_CONTACTSFORM };

BEGIN_MSG_MAP(CContactsForm)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
	COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
	CHAIN_MSG_MAP(CAxDialogImpl<CContactsForm>)
	COMMAND_HANDLER(IDC_BUTTON1, BN_CLICKED, OnBnClickedButton1)
	NOTIFY_HANDLER(IDC_LIST_CONTACT, NM_DBLCLK, OnNMDblclkListContact)
END_MSG_MAP()

// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		CAxDialogImpl<CContactsForm>::OnInitDialog(uMsg, wParam, lParam, bHandled);
		LoadContactForm();
		bHandled = TRUE;
		return 1;  // Let the system set the focus
	}

	LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

	LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		EndDialog(wID);
		return 0;
	}


private:
	Outlook::_Application* m_app;
	std::wstring mobiles;

private:
	void LoadContactForm();
	void InitListViewUI(HWND hListView);
	void InsertOneContactInListView(HWND hList, int index ,  LPCWSTR fullName , LPCWSTR mobile);
	void AppendMobileNumberToBox(LPCWSTR append);
	LRESULT EnumSelectitemInContactList();
public:
	LRESULT OnBnClickedButton1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnNMDblclkListContact(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/);
	LRESULT GetAppendContactList(std::wstring& mobiles);
};


